package com.lds.config.center.server.business.namespace.controller;

import com.lds.config.center.common.model.namespace.request.NamespaceBaseBatchCreateRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseBatchDeleteRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseBatchUpdateRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseCreateRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseDeleteRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseGetByIdRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseGetByIdsRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseGetByKeyRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseListPageRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseListRequest;
import com.lds.config.center.common.model.namespace.request.NamespaceBaseUpdateRequest;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseBatchCreateResponse;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseBatchDeleteResponse;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseBatchUpdateResponse;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseDeleteResponse;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseListResponse;
import com.lds.config.center.common.model.namespace.response.NamespaceBaseResponse;
import com.lds.config.center.server.business.namespace.service.NamespaceBaseService;
import com.lds.management.center.common.model.db.OrderBy;
import com.lds.management.center.common.model.db.PageResult;
import com.lds.management.center.common.model.dto.ResultDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2025-06-26
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/namespace")
public class NamespaceBaseController {

    private final NamespaceBaseService namespaceBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<NamespaceBaseResponse> createNamespace(@RequestBody @Validated NamespaceBaseCreateRequest request) {
        return namespaceBaseService.createNamespace(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<NamespaceBaseBatchCreateResponse> batchCreateNamespace(@RequestBody @Validated NamespaceBaseBatchCreateRequest request) {
        return namespaceBaseService.batchCreateNamespace(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<NamespaceBaseDeleteResponse> deleteNamespace(@RequestBody NamespaceBaseDeleteRequest request) {
        return namespaceBaseService.deleteNamespace(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<NamespaceBaseBatchDeleteResponse> batchDeleteNamespace(@RequestBody @Validated NamespaceBaseBatchDeleteRequest request) {
        return namespaceBaseService.batchDeleteNamespace(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<NamespaceBaseResponse> updateNamespace(@RequestBody @Validated NamespaceBaseUpdateRequest request) {
        return namespaceBaseService.updateNamespace(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<NamespaceBaseBatchUpdateResponse> batchUpdateNamespace(@RequestBody @Validated NamespaceBaseBatchUpdateRequest request) {
        return namespaceBaseService.batchUpdateNamespace(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<NamespaceBaseListResponse> listNamespace(@RequestBody NamespaceBaseListRequest request) {
        return namespaceBaseService.listNamespace(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<NamespaceBaseListResponse> listAllNamespace(@RequestBody OrderBy orderBy) {
        return namespaceBaseService.listAllNamespace(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<NamespaceBaseResponse> getNamespaceById(@RequestBody @Validated NamespaceBaseGetByIdRequest request) {
        return namespaceBaseService.getNamespaceById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<NamespaceBaseListResponse> getNamespaceByIds(@RequestBody @Validated NamespaceBaseGetByIdsRequest request) {
        return namespaceBaseService.getNamespaceByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<NamespaceBaseResponse>> listNamespacePage(@RequestBody NamespaceBaseListPageRequest request) {
        return namespaceBaseService.listNamespacePage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated NamespaceBaseGetByKeyRequest request) {
        return ResultDTO.success(namespaceBaseService.getNamespaceByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<NamespaceBaseBatchCreateResponse> batchCreateNamespaceAsync(@RequestBody @Validated NamespaceBaseBatchCreateRequest request) {
        return namespaceBaseService.batchCreateNamespaceAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<NamespaceBaseBatchDeleteResponse> batchDeleteNamespaceAsync(@RequestBody @Validated NamespaceBaseBatchDeleteRequest request) {
        return namespaceBaseService.batchDeleteNamespaceAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<NamespaceBaseBatchUpdateResponse> batchUpdateNamespaceAsync(@RequestBody @Validated NamespaceBaseBatchUpdateRequest request) {
        return namespaceBaseService.batchUpdateNamespaceAsync(request);
    }

}